<?php

namespace App\Http\Controllers\Admin;


use App\Models\Administrator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AdministratorController extends Controller
{
 
    public function index()
    {
        $administrators=Administrator::get();
        return view('admin.administrator.index',compact('administrators'));
    }

  
    public function create()
    {
        // 加载后台管理员模板
        return view('admin.administrator.create');
    }

    public function store(Request $request)
    {
//        dd($request->toArray());
        if (filter_var($request->account,FILTER_VALIDATE_EMAIL)){
            $request['email']=$request->account;
        }else{
            $request['phone']=$request->account;
        }
//        $request['password']=bcrypt($request->password,true);
        $request['icon']='https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=882282681,2313129323&fm=27&gp=0.jpg';
        Administrator::create($request->all());
        return redirect()->route('admin.administrator.index')->with('success','添加管理员成功');
    }

    
    public function show(Administrator $administrator)
    {
        //
    }

   
    public function edit(Administrator $administrator)
    {
        
        return view('admin.administrator.edit',compact('administrator'));
    }

   
    public function update(Request $request, Administrator $administrator)
    {
        $administrator->update($request->all());
        return redirect()->route('admin.administrator.index')->with('success','编辑成功');
    }

    public function destroy(Administrator $administrator)
    {
//        dd($administrator);
        $administrator->delete();
        return back()->with('success','删除成功');
    }
}
